package com.hengyue.system.repository;

import com.hengyue.system.domain.entity.SysDictData;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Set;

public interface SysDictDataRepository extends JpaRepository<SysDictData, Long>, JpaSpecificationExecutor<SysDictData> {

    // 新增按字典查询方法
    List<SysDictData> findByDictType(String dictType);

    // 新增按状态查询方法
    List<SysDictData> findByStatus(String status);

    @Query("SELECT DISTINCT d.dictType FROM SysDictData d WHERE d.dictType IN :dictTypes")
    Set<String> findDictTypesWithData(@Param("dictTypes") List<String> dictTypes);

    @Query("SELECT d.dictLabel FROM SysDictData d WHERE d.dictType = :dictType " +
            "AND d.dictValue = :dictValue AND d.status = '0'")
   String findByDictTypeAndDictValue(String dictType, String dictValue);
}
